﻿using System;
using System.IO;
using OscarCloverActivities.Packets;

namespace OscarCloverActivities.Packets
{
    public enum FrameTypes : byte
    {
        SignOn = 0x01,
        Data = 0x02,
        Error = 0x03,
        SignOff = 0x04,
        KeepAlive = 0x05
    }

    [Serializable]
    public abstract class Flap
    {
        private MemoryStream _data = new MemoryStream();
        public TlvList TlvList = new TlvList();
        public byte [] DataArray
        {
            get
            {
                return _data.ToArray();
            }
        }

        protected Flap()
        {
            Len = 0;
        }

        protected Flap(FrameTypes frameType)
        {
            FrameType = frameType;
            Len = 0;
        }

        public FrameTypes FrameType { get; set; }

        public ushort Len { get; set; }

        public void AddTlv(Tlv tlv)
        {
            TlvList.Add(tlv);
            Len += (ushort) (tlv.Len + 4);
        }

        public void AddData(byte[] data)
        {
            _data.Write(data, 0, data.Length);
            Len += (ushort) data.Length;
        }
    }
}